/*
  Copyright 2011 fullkawa

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package jp.fullkawa.xnovel;

import java.util.ArrayList;
import java.util.List;

public class XNovel
{
	private String title;

	/*
	 * 詳細情報
	 */
	private String creator;
	private String publisher;
	private String description;

	/**
	 * 縦横表示の可否
	 * 回転を許す方向を指定出来ます。ホームボタンの位置をテンキー方式（8642）で指定。
	 * "46"の指定なら横画面を許します。省略時はどの向きにも回転。
	 */
	private String direction;

	/**
	 * 縦書き・横書き固定
	 * "tb"の指定（top bottom）なら横書きのみ。縦書きのみは"rl"。
	 * 省略時は設定画面の設定に従う。
	 */
	private String textRotation;

	/**
	 * サポート端末
	 * 指定以外は実行出来ない。"iphone"指定はiPod Touchを含む。省略時はどれでもＯＫ。
	 */
	private String support;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	public String getPublisher() {
		return publisher;
	}

	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDirection() {
		return direction;
	}

	public void setDirection(String direction) {
		this.direction = direction;
	}

	public String getTextRotation() {
		return textRotation;
	}

	public void setTextRotation(String textRotation) {
		this.textRotation = textRotation;
	}

	public String getSupport() {
		return support;
	}

	public void setSupport(String support) {
		this.support = support;
	}

	/**
	 * リストの先頭に追加されたSceneが最初に表示される
	 */
	private List<Scene> contents = new ArrayList<Scene>();

	public List<Scene> getContents() {
		return contents;
	}

	public void setContents(List<Scene> contents) {
		this.contents = contents;
	}

	public void addScene(Scene scene)
	{
		this.contents.add(scene);
	}

	public String getTitleTag()
	{
		String tag = "<h1>"
			+ (this.getTitle()==null ? "" : this.getTitle())
			+ "</h1>";
		return tag;
	}

	public String getCreatorTag()
	{
		String tag = "<h2 id=\"creator\">"
			+ (this.getCreator()==null ? "" : this.getCreator())
			+ "</h2>";
		return tag;
	}

	public String getPublisherTag()
	{
		String tag = "<h2 id=\"publisher\">"
			+ (this.getPublisher()==null ? "" : this.getPublisher())
			+ "</h2>";
		return tag;
	}

	public String getDescriptionTag()
	{
		String tag = "<h2 id=\"description\">"
			+ (this.getDescription()==null ? "" : this.getDescription())
			+ "</h2>";
		return tag;
	}

	public String getContentsStartTag()
	{
	    StringBuilder tag = new StringBuilder();

	    tag.append("<div id=\"contents\" xn_direction=\"");
	    if (this.getDirection() != null) tag.append(this.getDirection());
	    tag.append("\" xn_text_rotation=\"");
	    if (this.getTextRotation() != null) tag.append(this.getTextRotation());
	    tag.append("\" xn_support=\"");
	    if (this.getSupport() != null) tag.append(this.getSupport());
	    tag.append("\">");

	    return tag.toString();
	}

	public String getContentsEndTag()
	{
	    return "</div>";
	}
}
